{include file="public/header" /}
<title>帖子{notempty name="user_posts"}修改{else/ }发布{/notempty}</title>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>帖子{notempty name="user_posts"}修改{else/ }发布{/notempty}</legend>
</fieldset>

<!-- 加载编辑器的容器 -->

<!-- 配置文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>

<form class="layui-form" action="" method="post" enctype="multipart/form-data">

    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">文章设置</li>
            <li>文章内容</li>

        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                {notempty name="user_posts"} <input type="hidden" name="id" value="{$user_posts.id}"> {/notempty}

                <div class="layui-form-item">
                    <label class="layui-form-label">帖子标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="post_title" required {notempty name="user_posts"} value="{$user_posts.post_title}" {/notempty} lay-verify="required" placeholder="请输入帖子标题" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div style="margin-left: 110px;">
                    <input id="filed" name="post_img" type="file" {empty name="user_posts"} required lay-verify="required" {/empty}  style="display:none;">
                    <button type="button" class="layui-btn" id="my-img"><i class="layui-icon">&#xe67c;</i>上传文章封面</button>

                    <div id="box" style="margin: 20px 0 20px 0">
                        <img id="imgshow" {notempty name="user_posts"} src="http://www.2021rbac.com/{$user_posts.post_img}" {/notempty}/>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">文章分类</label>
                    <div class="layui-input-block">
                        <select name="cate_id" lay-verify="required">
                            <option value=""></option>
                            {foreach $cate as $v}
                            <option value="{$v.id}" {notempty name="user_posts"}{if $user_posts.cate_id == $v.id}selected{/if}{/notempty} >{$v.cate_name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="0" {notempty name="user_posts"}{if $user_posts.status == 0}checked{/if}{else /}checked{/notempty} title="发布">
                        <input type="radio" name="status" value="1" {notempty name="user_posts"}{if $user_posts.status == 1}checked{/if}{/notempty} title="未发布" >
                    </div>
                </div>

            </div>
            <div class="layui-tab-item">
                <blockquote class="layui-elem-quote">文章内容</blockquote>

                <script id="container" name="post_content" style="height: 300px;display: block" type="text/plain">
                    <?php
                        if(!empty($user_posts)){
                            echo $user_posts['post_content'];
                        }
                    ?>
                </script>
            </div>

        </div>
    </div>




    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<style>
    #box {
        width: 120px;
        height: 120px;

    }

    #imgshow {
        width: 100%;
        height: 100%;
    }
</style>



<script>
    $("#filed").change(function(){
        $("#imgshow").attr("src",URL.createObjectURL($(this)[0].files[0]));
    });

    $(document).ready(function(){
        $('#my-img').click(function(){
            $('#filed').click();
        });

    });
</script>

<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){

        });
    });
</script>

{include file="public/footer" /}